#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e5+100;
typedef long long LL;
const LL mod=1e9+7;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
struct Edge{
    LL to;
    char op;
};
vector<Edge>g[maxn];
LL val[maxn],fat[maxn];
char str[maxn];
LL dp[maxn];
LL ksm(LL a,LL k){
    LL res=1;
    while(k>0){
        if(k&1) res=res*a%mod;
        k>>=1;
        a=a*a%mod;
    }
    return res%mod;
}
void dfs(LL u,LL fa,LL ye,LL sum,LL mul,char nowop,char lastop){
    if(fa==0) dp[u]=sum;
    else{
        if(nowop=='+') dp[u]=(dp[fa]%mod+val[u]%mod)%mod;
        if(nowop=='-') dp[u]=((dp[fa]%mod-val[u]%mod)%mod+mod)%mod;
        if(nowop=='*'){
            if(lastop=='*'||lastop=='0'||lastop=='/') dp[u]=(dp[fa]%mod*val[u]%mod)%mod;
            else{
                if(lastop=='+') dp[u]=(val[u]%mod*val[fa]%mod+dp[ye]%mod)%mod;
                if(lastop=='-') dp[u]=(dp[ye]%mod-(val[u]%mod*val[fa]%mod)%mod+mod)%mod;
            }
        }
        if(nowop=='/'){
            if(lastop=='/'||lastop=='0'||lastop=='*') dp[u]=(dp[fa]%mod*ksm(val[u],mod-2)%mod)%mod;
            else {
                if(lastop=='+') dp[u]=(val[fa]%mod*ksm(val[u],mod-2)%mod+dp[ye]%mod)%mod;
                if(lastop=='-') dp[u]=(dp[ye]%mod-(val[fa]%mod*ksm(val[u],mod-2)%mod)%mod+mod)%mod;
            }
        }
    }
    for(LL i=0;i<g[u].size();i++){
        LL v=g[u][i].to;
        if(v==fa) continue;
        dfs(v,u,fa,dp[u],g[u][i].op,nowop);
    }
}
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  LL n;cin>>n;
  for(LL i=1;i<=n;i++) cin>>val[i];
  for(LL i=2;i<=n;i++) cin>>fat[i];
  for(LL i=2;i<=n;i++) cin>>str[i];
  for(LL i=2;i<=n;i++){
    LL u=fat[i];
    g[u].push_back({i,str[i]});
  }
  dfs(1,0,-1,val[1],'0','0');
  for(LL i=1;i<=n;i++){
    cout<<dp[i]<<" ";
  }
  cout<<"\n";
return 0;
}
